
const createdwork = {
    // 获取工单分类名
    getcreatedWorkText: function (callback) {
        this.public('/admin/workorderclassify',{},callback);
    },

    //获取用户列表
    getAdminUser:function(page,limit,username,customer_sn,nickname,realname,status,type,phone,qq,callback){
            this.public('/admin/users',{
                page:page,
                limit:limit,
                username:username,
                customer_sn:customer_sn,
                nickname:nickname,
                realname:realname,
                status:status,
                type:type,
                phone:phone
            },callback);
    },

    //添加工单
    getAddWorkText:function(title,classify_id,depiction,customer_id,priority,status,source,assign_user_id,cc_user_id,enclosure,callback) {
        this.public('/admin/WorkOrders/save',{
            title:title,       //标题
            classify_id:classify_id,   //分类
            depiction:depiction,        //描述
            customer_id:customer_id,    //客户id
            priority:priority,          //优先级
            status:status,              //状态
            source:source,              //来源
            assign_user_id:assign_user_id,  //客服id
            cc_user_id:cc_user_id,          //抄送客服id
            deadline_time:Math.round(new Date().getTime() / 1000).toString(), //截止时间,
            enclosure:enclosure,     //附件
        },callback);

    },

    //公共请求的function
    public: function (methods, data, success, error) {
        let xhr = new XMLHttpRequest();
        let formData = new FormData();
        for (let key in data) {
            formData.append(key, data[key]);
        }
        formData.append("authkey", localStorage.getItem("authkey"));
        formData.append("sessionid", localStorage.getItem("sessionid"));

        xhr.open("post", process.env.API_URL + methods);
        xhr.send(formData);
        xhr.onreadystatechange = function () {
            if (xhr.status === 200) {
                if (xhr.readyState === 4) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (success) success(responseData);
                }
            } else {
                if (errorHandler) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (error) error(responseData);
                } else {
                    alert("请求失败！" + xhr.responseText);
                }
            }
        };
    }
};

export default createdwork;





